//
//  feedBackNormalQuesCell.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/4/12.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class feedBackNormalQuesCell: UITableViewCell {

    var dotView:UIView?
    //问题
    var titleText:UILabel?
    //内容
    var contextText:UILabel?
    var diviline:UIImageView?
    var attrString:NSMutableAttributedString?// = NSMutableAttributedString()
    
    var model:feedBackNormalQuesCellModel? {
        didSet{
            updateContent()
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setDefalutContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setDefalutContent() {
        
        selectionStyle = UITableViewCellSelectionStyle.None
        backgroundColor = LDGolbalColor.BgGoundGray
    
        titleText = UILabel.setDetailsLab("", fontSize: 14, titleColor: LDFontColor.DeepBlack, Alignment: .Left)
        titleText?.numberOfLines = 0
        
        contextText = UILabel.setDetailsLab("", fontSize: 13, titleColor: LDFontColor.LightBlack, Alignment: .Left)
        contextText?.numberOfLines = 0
        contextText?.lineBreakMode = NSLineBreakMode.ByWordWrapping
        
        
        diviline = UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - LDMargin_H*8)
        dotView = UIView.init()
        dotView?.backgroundColor = LDIconColor.Black
        
        
        addSubview(titleText!)
        addSubview(contextText!)
        addSubview(diviline!)
        addSubview(dotView!)
        
        
        dotView?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(30)
            make.left.equalTo(35)
            make.height.width.equalTo(5)
        })
        
        titleText?.snp_makeConstraints(closure: { (make) in
            //make.centerY.equalTo(dotView!)
            make.top.equalTo(dotView!).offset(-7)
            make.left.equalTo((dotView?.snp_right)!).offset(LDMargin_H)
            make.width.equalTo(LDFrame.ScreenWidth - (35*2 + 10))
        })
        contextText?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((titleText?.snp_bottom)!).offset(LDMargin_H*2)
            make.left.equalTo(titleText!)
            make.width.equalTo(LDFrame.ScreenWidth - (35*2 + 10))
        })
        diviline?.snp_makeConstraints(closure: { (make) in
            
            make.left.equalTo(dotView!)
            make.right.equalTo(-35)
            make.bottom.equalTo(self)
            make.height.equalTo(1)
        })
        
    }
    
    func updateContent() {
        
        titleText?.text = model?.question
        attrString = String.getAttrFormString(lineH: 10, text: (model?.answer)!, font: LDFont.Font13)
        contextText?.attributedText = attrString
        
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }

}
class feedBackNormalQuesCellModel: NSObject {
    
    lazy var height:CGFloat = {
        
        let size = CGSizeMake(LDFrame.ScreenWidth - (35*2 + 10), CGFloat.max)
        
        let descH:CGFloat = (String.getHeightFormAttr(10, title: self.answer!, size: size,font: LDFont.Font13))
        let qusetH:CGFloat = (String.getHeightFormAttr(10, title: self.question!, size: size,font: LDFont.Font14))
        
        self.descHeight = descH
        
        let allH = descH + qusetH + 25 + 20 //标题上边距固定高度
        return allH
    }()
    
    var descHeight:CGFloat = 0
    
    var id:Int?
    var question:String?
    var answer:String?
}